const { readFileSync, writeFileSync } = require('fs')
const getip = require('./getip')



module.exports = (url) => {
    const content = readFileSync(url).toString()
    const data = JSON.parse(content)
    const ip = getip()

    for (const key in data) {
        data[key] = data[key].map((item, index) => {
            item.img = `http://${ip}:8888/images/${key + (index + 1)}.jpg`
            item.id = Math.floor(Math.random()*100000000)
            return item
        })
    }
    writeFileSync(url, JSON.stringify(data))

}
